package com.soulgame.sms.pay.vo;

import com.soul.sdk.utils.json.KJSONObject;
import com.soulgame.sgsdkproject.sgtool.AmountUtils;

/**
 * @author lch
 * @version Create time：2017-3-24
 * @类说明：
 */
public abstract class VoPayParams {

	private KJSONObject mSdkParamsJSON;

	protected KJSONObject mPayDataJSON;

	public VoPayParams(KJSONObject pSdkParamsJSON) {
		this.mSdkParamsJSON = pSdkParamsJSON;
		if (pSdkParamsJSON != null) {
			this.mPayDataJSON = pSdkParamsJSON.getJSONObject("payData");
		}
	}

	public KJSONObject getSdkParamsJSON() {
		return mSdkParamsJSON;
	}

	public String getGameName() {
		String gameName = "";
		if (mSdkParamsJSON != null) {
			gameName = mSdkParamsJSON.optString("gameName");
		}
		return gameName;
	}
	
	/**
	 * 拼装下单rul用到的 游戏昵称字段
	 * @return
	 */
	public String getUrlNickname() {
		String urlNickname = "";
		if (mSdkParamsJSON != null) {
			urlNickname = mSdkParamsJSON.optString("urlNickname");
		}
		return urlNickname;
	}

	/**
	 * 获取计费点，缺省返回 0
	 * 
	 * @param pProductId
	 * @return
	 */
	protected String getPayCode(String pProductId, String pPayTypeKey) {
		String aPayCode = "0";
		if (mPayDataJSON != null) {
			KJSONObject productDataJSON = mPayDataJSON.getJSONObject(pProductId);
			if (productDataJSON != null) {
				KJSONObject aDataJSON = productDataJSON.getJSONObject(pPayTypeKey);
				if (aDataJSON != null) {
					aPayCode = aDataJSON.getString("paycode", "0");
				}
			}
		}
		return aPayCode;
	}

	/**
	 * 商品名称
	 * 
	 * @param pProductId
	 * @return
	 */
	public String getPayProductName(String pProductId) {
		String aName = "";
		if (mPayDataJSON != null) {
			KJSONObject productDataJSON = mPayDataJSON.getJSONObject(pProductId);
			if (productDataJSON != null) {
				aName = productDataJSON.getString("name", "");
			}
		}
		return aName;
	}

	/**
	 * 获取价格，并转换为元
	 * 
	 * @param pProductId
	 * @return
	 */
	public String getPayPrice(String pProductId) {
		String aPrice = "0";
		if (mPayDataJSON != null) {
			KJSONObject productDataJSON = mPayDataJSON.getJSONObject(pProductId);
			if (productDataJSON != null) {
				String fPrice = productDataJSON.getString("price", "0");
				// 分转为元
				aPrice = AmountUtils.changeF2Y(fPrice);
			}
		}
		return aPrice;
	}
}
